using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using cframework_xlua;
using System.ComponentModel;
using Newtonsoft.Json;
namespace cframework_xlua
{
    [CreateAssetMenu(menuName = "cframework_xlua/PublishUtil_WebGL")]
    public class PublishUtil_WebGL : PlatformPublishUtil
    {
        public override bool BuildAndPublish(BuildPlayerSetting setting, BuildPlayerSetting.PublishInfo publishInfo)
        {
            var ossDir = $"{publishInfo.appName}/{publishInfo.middleDir}/{publishInfo.hotupdateVersionNumber}_{publishInfo.timestamp}";

            string downloadUrl = null;
            if (setting.channelUtil.Deploy(setting, publishInfo.outputProjectPath, ossDir, null, ref downloadUrl))
            {
                setting.StartHttpServer();
            }
            else
            {
                return false;
            }

            string playUrl = downloadUrl + "/index.html";
            Debug.Log("play url: " + downloadUrl);
            if (EditorUtility.DisplayDialog("play url", playUrl, "copy", "ok"))
            {
                GUIUtility.systemCopyBuffer = playUrl;
            }
            else
                return false;

            return true;
        }


    }
}